﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RiskMan.DataClass;
using System.Diagnostics;
using TheControllerRisk.Settings;
using System.Reflection;

namespace RiskMan.Config
{
    internal class ProcessCheck
    {
        private const string _processName = "info";
        private List<String> _pathList = new List<string>( );
        private Data _data;


        public ProcessCheck ( )
        {
            _data = RiskMan.MainWindow.StaticLedder._dataProvider;
        }

        public bool Check ( )
        {
            bool result = false;
           // int index = 0;
            var process = Process.GetProcesses( ).ToList( );

            // cfg.SetLog( "Название: " + tmp.Name + " Путь: " + tmp.Path + " Error: " + ex.Message, MainWindow.StaticRiskMan.ListBox_Logs );

            foreach ( var tmp in _data.T2QItems )
            {
                string message = tmp.Name;
                
                for ( int i = 0; i < process.Count; i++ )
                {
                    try
                    {
                        if ( process [ i ].ProcessName == "info" && process [ i ].MainModule.FileName == tmp.Path + "\\info.exe" )
                        {
                            message = tmp.Name;
                            break;
                        }
                    }
                    catch ( Exception ex )
                    {
                        message = ex.Message;
                    }
                }

                if ( message != tmp.Name )
                {
                    cfg.SetLog( "Название: " + tmp.Name + " Error: " + message, MainWindow.StaticLedder.ListBox_Logs, GetType( ), MethodBase.GetCurrentMethod( ) );
                }
            }

                return result;
        }
    }
}